package org.freez4.spring.ioc.overview.repository;

import org.freez4.spring.ioc.overview.domain.User;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.ObjectFactory;
import org.springframework.context.ApplicationContext;

import java.util.Collection;

/**
 * 用户信息仓库
 * <p>
 * Spring IoC 依赖来源
 * 1. 自定义Bean
 * 2. 内置Bean
 * 3. 内置非Bean
 *
 * @author 阿坤同学
 * @date 2023/12/3 21:33
 */
public class UserRepository {

    /**
     * 实时注入
     */
    private Collection<User> users;

    /**
     * 延迟注入。
     * 通过间接的方式创建 <T> T 泛型的对象。
     */
    private ObjectFactory<User> objectFactory;

    /**
     * 注入内建非Bean（依赖）
     */
    private BeanFactory beanFactory;

    /**
     * 内置Bean
     * <p>
     * 注入IoC 应用上下文。
     */
    private ObjectFactory<ApplicationContext> applicationContextObjectFactory;

    public Collection<User> getUsers() {
        return users;
    }

    public void setUsers(Collection<User> users) {
        this.users = users;
    }

    public ObjectFactory<User> getObjectFactory() {
        return objectFactory;
    }

    public void setObjectFactory(ObjectFactory<User> objectFactory) {
        this.objectFactory = objectFactory;
    }

    public BeanFactory getBeanFactory() {
        return beanFactory;
    }

    public void setBeanFactory(BeanFactory beanFactory) {
        this.beanFactory = beanFactory;
    }

    public ObjectFactory<ApplicationContext> getApplicationContextObjectFactory() {
        return applicationContextObjectFactory;
    }

    public void setApplicationContextObjectFactory(ObjectFactory<ApplicationContext> applicationContextObjectFactory) {
        this.applicationContextObjectFactory = applicationContextObjectFactory;
    }

    @Override
    public String toString() {
        return "UserRepository{" + ",\n" +
                "users=" + users + ",\n" +
                " objectFactory=" + objectFactory + ",\n" +
                " beanFactory=" + beanFactory + ",\n" +
                " applicationContextObjectFactory=" + applicationContextObjectFactory + ",\n" +
                '}';
    }
}
